home *** CD-ROM | disk | FTP | other *** search
/ PC World 2008 March / PCWorld_2008-03_cd.bin / v cisle / mobiDVD / MobiDVD-1.0.0.6.exe / xulrunner / components / nsDefaultCLH.js < prev    next >
Text File  |  2007-07-27  |  6KB  |  198 lines

  1. //@line 38 "/cygdrive/d/builds/tinderbox/XR-Trunk/WINNT_5.2_Depend/mozilla/toolkit/components/nsDefaultCLH.js"
  2.  
  3. const nsISupports              = Components.interfaces.nsISupports;
  4.  
  5. const nsICategoryManager       = Components.interfaces.nsICategoryManager;
  6. const nsIComponentRegistrar    = Components.interfaces.nsIComponentRegistrar;
  7. const nsICommandLine           = Components.interfaces.nsICommandLine;
  8. const nsICommandLineHandler    = Components.interfaces.nsICommandLineHandler;
  9. const nsIFactory               = Components.interfaces.nsIFactory;
  10. const nsIModule                = Components.interfaces.nsIModule;
  11. const nsIPrefBranch            = Components.interfaces.nsIPrefBranch;
  12. const nsISupportsString        = Components.interfaces.nsISupportsString;
  13. const nsIWindowWatcher         = Components.interfaces.nsIWindowWatcher;
  14. const nsIProperties            = Components.interfaces.nsIProperties;
  15. const nsIFile                  = Components.interfaces.nsIFile;
  16. const nsISimpleEnumerator      = Components.interfaces.nsISimpleEnumerator;
  17.  
  18. /**
  19.  * This file provides a generic default command-line handler.
  20.  *
  21.  * It opens the chrome window specified by the pref "toolkit.defaultChromeURI"
  22.  * with the flags specified by the pref "toolkit.defaultChromeFeatures"
  23.  * or "chrome,dialog=no,all" is it is not available.
  24.  * The arguments passed to the window are the nsICommandLine instance.
  25.  *
  26.  * It doesn't do anything if the pref "toolkit.defaultChromeURI" is unset.
  27.  */
  28.  
  29. function getDirectoryService()
  30. {
  31.   return Components.classes["@mozilla.org/file/directory_service;1"]
  32.                    .getService(nsIProperties);
  33. }
  34.  
  35. var nsDefaultCLH = {
  36.   /* nsISupports */
  37.  
  38.   QueryInterface : function clh_QI(iid) {
  39.     if (iid.equals(nsICommandLineHandler) ||
  40.         iid.equals(nsIFactory) ||
  41.         iid.equals(nsISupports))
  42.       return this;
  43.  
  44.     throw Components.results.NS_ERROR_NO_INTERFACE;
  45.   },
  46.  
  47.   /* nsICommandLineHandler */
  48.  
  49.   handle : function clh_handle(cmdLine) {
  50.     var printDir;
  51.     while (printDir = cmdLine.handleFlagWithParam("print-xpcom-dir", false)) {
  52.       var out = "print-xpcom-dir(\"" + printDir + "\"): ";
  53.       try {
  54.         out += getDirectoryService().get(printDir, nsIFile).path;
  55.       }
  56.       catch (e) {
  57.         out += "<Not Provided>";
  58.       }
  59.  
  60.       dump(out + "\n");
  61.       Components.utils.reportError(out);
  62.     }
  63.  
  64.     var printDirList;
  65.     while (printDirList = cmdLine.handleFlagWithParam("print-xpcom-dirlist",
  66.                                                       false)) {
  67.       out = "print-xpcom-dirlist(\"" + printDirList + "\"): ";
  68.       try {
  69.         var list = getDirectoryService().get(printDirList,
  70.                                              nsISimpleEnumerator);
  71.         while (list.hasMoreElements())
  72.           out += list.getNext().QueryInterface(nsIFile).path + ";";
  73.       }
  74.       catch (e) {
  75.         out += "<Not Provided>";
  76.       }
  77.  
  78.       dump(out + "\n");
  79.       Components.utils.reportError(out);
  80.     }
  81.  
  82.     if (cmdLine.preventDefault)
  83.       return;
  84.  
  85.     var prefs = Components.classes["@mozilla.org/preferences-service;1"]
  86.                           .getService(nsIPrefBranch);
  87.  
  88.     try {
  89.       var singletonWindowType =
  90.                               prefs.getCharPref("toolkit.singletonWindowType");
  91.       var windowMediator =
  92.                 Components.classes["@mozilla.org/appshell/window-mediator;1"]
  93.                           .getService(Components.interfaces.nsIWindowMediator);
  94.  
  95.       var win = windowMediator.getMostRecentWindow(singletonWindowType);
  96.       if (win) {
  97.         win.focus();
  98.         cmdLine.preventDefault = true;
  99.       return;
  100.       }
  101.     }
  102.     catch (e) { }
  103.  
  104.     // if the pref is missing, ignore the exception 
  105.     try {
  106.       var chromeURI = prefs.getCharPref("toolkit.defaultChromeURI");
  107.  
  108.       var flags = "chrome,dialog=no,all";
  109.       try {
  110.         flags = prefs.getCharPref("toolkit.defaultChromeFeatures");
  111.       }
  112.       catch (e) { }
  113.  
  114.       var wwatch = Components.classes["@mozilla.org/embedcomp/window-watcher;1"]
  115.                             .getService(nsIWindowWatcher);
  116.       wwatch.openWindow(null, chromeURI, "_blank",
  117.                         flags, cmdLine);
  118.     }
  119.     catch (e) { }
  120.   },
  121.  
  122.   helpInfo : "",
  123.  
  124.   /* nsIFactory */
  125.  
  126.   createInstance : function mdh_CI(outer, iid) {
  127.     if (outer != null)
  128.       throw Components.results.NS_ERROR_NO_AGGREGATION;
  129.  
  130.     return this.QueryInterface(iid);
  131.   },
  132.  
  133.   lockFactory : function mdh_lock(lock) {
  134.     /* no-op */
  135.   }
  136. };
  137.  
  138. const clh_contractID = "@mozilla.org/toolkit/default-clh;1";
  139. const clh_CID = Components.ID("{6ebc941a-f2ff-4d56-b3b6-f7d0b9d73344}");
  140.  
  141. var Module = {
  142.   /* nsISupports */
  143.  
  144.   QueryInterface : function mod_QI(iid) {
  145.     if (iid.equals(nsIModule) ||
  146.         iid.equals(nsISupports))
  147.       return this;
  148.  
  149.     throw Components.results.NS_ERROR_NO_INTERFACE;
  150.   },
  151.  
  152.   /* nsIModule */
  153.  
  154.   getClassObject : function mod_gch(compMgr, cid, iid) {
  155.     if (cid.equals(clh_CID))
  156.       return nsDefaultCLH.QueryInterface(iid);
  157.  
  158.     throw components.results.NS_ERROR_FAILURE;
  159.   },
  160.  
  161.   registerSelf : function mod_regself(compMgr, fileSpec, location, type) {
  162.     var compReg = compMgr.QueryInterface(nsIComponentRegistrar);
  163.  
  164.     compReg.registerFactoryLocation(clh_CID,
  165.                                     "nsDefaultCLH",
  166.                                     clh_contractID,
  167.                                     fileSpec,
  168.                                     location,
  169.                                     type);
  170.  
  171.     var catMan = Components.classes["@mozilla.org/categorymanager;1"]
  172.                            .getService(nsICategoryManager);
  173.  
  174.     catMan.addCategoryEntry("command-line-handler",
  175.                             "y-default",
  176.                             clh_contractID, true, true);
  177.   },
  178.  
  179.   unregisterSelf : function mod_unreg(compMgr, location, type) {
  180.     var compReg = compMgr.QueryInterface(nsIComponentRegistrar);
  181.     compReg.unregisterFactoryLocation(clh_CID, location);
  182.  
  183.     var catMan = Components.classes["@mozilla.org/categorymanager;1"]
  184.                            .getService(nsICategoryManager);
  185.  
  186.     catMan.deleteCategoryEntry("command-line-handler",
  187.                                "y-default");
  188.   },
  189.  
  190.   canUnload : function (compMgr) {
  191.     return true;
  192.   }
  193. };
  194.  
  195. function NSGetModule(compMgr, fileSpec) {
  196.   return Module;
  197. }
  198.